/*
 * randomgraph.cpp
 *
 *  Created on: 13 oct. 2011
 *      Author: gtempier
 */
#include <time.h>
#include <cstdlib>
#include "randomgraph.h"

RandomGraph::RandomGraph(int nbVertex, float proba) : Graph()
{
	generateRandomGraph(nbVertex, proba);
}

void
RandomGraph::generateRandomGraph(int nbVertex, float proba) {
	srand(time(NULL));
	if (nbVertex < 1)
		return;
	int i = addVertex();
	while (i < nbVertex-1) {
		i = addVertex();
		for (int j=i-1; j>=0; j--) {
			double r = rand()/(double)RAND_MAX;
			if(r < proba)
				addEdge(j, i);
		}
	}
}
